package com.crm.backend.view;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String username=req.getParameter("username");
		String password=req.getParameter("password");
		String checkcode = req.getParameter("checkcode"); //用户输入的验证码
		//系统判断验证码是否正确
		//刚刚生成的验证码串(session中)
		String sessionCodes =(String) req.getSession().getAttribute("codes");
		
		//如果用户输入的验证码和生成的验证码不一致，则重定向到[forward]登陆页面
		if(!sessionCodes.equalsIgnoreCase(checkcode)){
			req.setAttribute("error", "验证码错误");
			//重定向到[forward]登陆页面
			req.getRequestDispatcher("/backend/login.jsp").forward(req, resp);
			return;
		}
		super.doPost(req, resp);
	}
	
}
